package com.shanzhu.book.mq;

import com.shanzhu.book.config.RabbitMQConfig;
import com.shanzhu.book.model.SeatReservation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class SeatMessageProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Value("${spring.custom.rabbitmq.seat.exchange}")
    private String seatExchange;

    public void sendReservationMessage(SeatReservation reservation) {
        rabbitTemplate.convertAndSend(seatExchange, 
                                    RabbitMQConfig.RESERVATION_ROUTING_KEY,
                                    reservation);
    }

    public void sendCancelMessage(Long reservationId) {
        rabbitTemplate.convertAndSend(seatExchange, 
                                    RabbitMQConfig.CANCEL_ROUTING_KEY, 
                                    reservationId);
    }
}